package com.l;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 代码生成
 */
public class T {
    public static void main(String[] args) {
        service("Factory","工厂");
    }
    public static void service(String engName,String zhName) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
        String formatDate = dateFormat.format(new Date());
        char[] chars = engName.toCharArray();
        chars[0] += 32;
        String lowerEngName = String.valueOf(chars);
        String serviceCode ="package com.zhwl.live.service;\n" +
                "/**\n" +
                " * <p>\n" +
                " *  服务类\n" +
                " * </p>\n" +
                " *\n" +
                " * @author xyh\n" +
                " * @since "+formatDate+"\n" +
                " */\n" +
                "public interface "+ engName +"Service {\n" +
                "\n" +
                "    /***\n" +
                "     * @desc 分页获取"+zhName+"信息\n" +
                "     * @author xyh\n" +
                "     * @update xyh\n" +
                "     * @date "+formatDate+"\n" +
                "     * @param pageNum 接收参数\n" +
                "     * @return 返回结果\n" +
                "     */\n" +
                "    PageInfo<"+ engName +"> get"+ engName +"List(int pageNum);\n" +
                "\n" +
                "    /**\n" +
                "     * 根据主键删除"+zhName+"\n" +
                "     * @author xyh\n" +
                "     * @update xyh\n" +
                "     * @date "+formatDate+"\n" +
                "     * @param id 主键\n" +
                "     */\n" +
                "    void del"+ engName +"(Integer id);\n" +
                "\n" +
                "    /**\n" +
                "     * 添加"+zhName+"\n" +
                "     * @author xyh\n" +
                "     * @update xyh\n" +
                "     * @date "+formatDate+"\n" +
                "     * @param inDto "+zhName+"数据传输接收参数\n" +
                "     * @return 成功或失败\n" +
                "     */\n" +
                "    Response<String> add"+ engName +"("+ engName +"InDto inDto);\n" +
                "\n" +
                "    /**\n" +
                "     * 根据主键获取一条"+zhName+"信息\n" +
                "     * @author xyh\n" +
                "     * @update xyh\n" +
                "     * @date "+formatDate+"\n" +
                "     * @param id 主键\n" +
                "     * @return  "+zhName+"数据传输输出实体\n" +
                "     */\n" +
                "    Response<"+ engName +"OutDto> get"+ engName +"(Integer id);\n" +
                "\n" +
                "    /**\n" +
                "     * 更新"+zhName+"信息\n" +
                "     * @author xyh\n" +
                "     * @update xyh\n" +
                "     * @date "+formatDate+"\n" +
                "     * @param inDto "+zhName+"数据传输接收参数\n" +
                "     * @return 成功或失败\n" +
                "     */\n" +
                "    Response<String> update"+ engName +"("+ engName +"InDto inDto);\n" +
                "    \n" +
                "}\n";
        String serviceStubCode = "package com.zhwl.live.service.stub;\n" +
                "/**\n" +
                " * @Description: "+zhName+"业务逻辑本地存根\n" +
                " * @author: xyh\n" +
                " * @date: "+formatDate+"\n" +
                " */\n" +
                "public class "+engName+"ServiceStub implements "+engName+"Service {\n" +
                "    private final "+engName+"Service "+lowerEngName+"Service;\n" +
                "\n" +
                "    /***\n" +
                "     * @desc 构造函数\n" +
                "     * @author xyh\n" +
                "     * @update xyh\n" +
                "     * @date "+formatDate+"\n" +
                "     * @param "+lowerEngName+"Service 的远程代理对象\n" +
                "     */" +
                "    public "+engName+"ServiceStub("+engName+"Service "+lowerEngName+"Service) {\n" +
                "        this."+lowerEngName+"Service = "+lowerEngName+"Service;\n" +
                "    }\n" +
                "\n" +
                "    public PageInfo<"+engName+"> get"+engName+"List(int pageNum){\n" +
                "        return "+lowerEngName+"Service.get"+engName+"List(pageNum);\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public void del"+engName+"(Integer id) {\n" +
                "        "+lowerEngName+"Service.del"+engName+"(id);\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public Response<String> add"+engName+"("+engName+"InDto inDto) {\n" +
                "        return "+lowerEngName+"Service.add"+engName+"(inDto);\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public Response<"+engName+"OutDto> get"+engName+"(Integer id) {\n" +
                "        return "+lowerEngName+"Service.get"+engName+"(id);\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public Response<String> update"+engName+"("+engName+"InDto inDto) {\n" +
                "        return "+lowerEngName+"Service.update"+engName+"(inDto);\n" +
                "    }\n" +
                "\n" +
                "}";
        String serviceImplCode = "package com.zhwl.live.service.impl;\n" +
                "/**\n" +
                " * @Description: "+zhName+"业务逻辑层实现\n" +
                " * @author: xyh\n" +
                " * @date: "+formatDate+"\n" +
                " */\n" +
                "@Service\n" +
                "@Component\n" +
                "@Slf4j\n" +
                "public class "+engName+"ServiceImpl implements "+engName+"Service {\n" +
                "    @Autowired\n" +
                "    private "+engName+"Mapper "+lowerEngName+"Mapper;\n" +
                "    @Override\n" +
                "    public PageInfo<"+engName+"> get"+engName+"List(int pageNum) {\n" +
                "        PageHelper.startPage(pageNum, 2);\n" +
                "        List<"+engName+"> "+lowerEngName+"List = "+lowerEngName+"Mapper.get"+engName+"List();\n" +
                "        return new PageInfo<>("+lowerEngName+"List, 3);\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public void del"+engName+"(Integer id) {\n" +
                "        "+lowerEngName+"Mapper.del"+engName+"(id);\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public Response<String> add"+engName+"("+engName+"InDto inDto) {\n" +
                "        "+engName+" "+lowerEngName+" = DozerMapperUtils.copyProperties(inDto, "+engName+".class);\n" +
                "        int result = "+lowerEngName+"Mapper.add"+engName+"("+lowerEngName+");\n" +
                "        return result == 1 ? Response.success(\"添加成功\") : Response.error(\"添加失败，请稍后重试\");\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public Response<"+engName+"OutDto> get"+engName+"(Integer id) {\n" +
                "        "+engName+" "+lowerEngName+" = "+lowerEngName+"Mapper.get"+engName+"(id);\n" +
                "        "+engName+"OutDto "+lowerEngName+"OutDto = DozerMapperUtils.copyProperties("+lowerEngName+", "+engName+"OutDto.class);\n" +
                "        return Response.success(\"获取成功\","+lowerEngName+"OutDto);\n" +
                "    }\n" +
                "\n" +
                "    @Override\n" +
                "    public Response<String> update"+engName+"("+engName+"InDto inDto) {\n" +
                "        "+engName+" "+lowerEngName+" = DozerMapperUtils.copyProperties(inDto, "+engName+".class);\n" +
                "        int result = "+lowerEngName+"Mapper.update"+engName+"("+lowerEngName+");\n" +
                "        return result == 1 ? Response.success(\"更新成功\") : Response.error(\"更新失败，请稍后重试\");\n" +
                "    }\n" +
                "    \n" +
                "}";
        String comm="\n" +
                "import lombok.Getter;\n" +
                "import lombok.Setter;\n" +
                "\n" +
                "import java.io.Serializable;\n" +
                "\n" +
                "/**\n" +
                " * @Description: "+zhName+"接收参数\n" +
                " * @author: xyh\n" +
                " * @date: "+formatDate+"\n" +
                " */\n" +
                "@Getter\n" +
                "@Setter\n";
        String inVoCode="package com.zhwl.live.entity.vo.input."+lowerEngName+";\n"+
                "public class "+engName+"InVo implements Serializable {\n" +
                "    private static final long serialVersionUID=1L;\n" +
                "}\n";
        String inDtoCode="package com.zhwl.live.dto.input."+lowerEngName+";\n"+
                "public class "+engName+"InDto implements Serializable {\n" +
                "    private static final long serialVersionUID=1L;\n" +
                "}\n";
        String outVoCode="public class "+engName+"OutVo implements Serializable {\n" +
                "    private static final long serialVersionUID=1L;\n" +
                "}\n";
        String outDtoCode="package com.zhwl.live.dto.output."+lowerEngName+";\n"+
                "public class "+engName+"OutDto implements Serializable {\n" +
                "    private static final long serialVersionUID=1L;\n" +
                "}\n";
        String projectPath = System.getProperty("user.dir");
        //D:\BaiduNetdiskDownload\xm\zhwl-live-parent\zhwl-live-service\zhwl-live-service-main\src\main\java\com\zhwl\live\service\GuildMemberService.java
        File service =new File("D:\\BaiduNetdiskDownload\\xm\\zhwl-live-parent\\zhwl-live-service\\zhwl-live-service-main\\src\\main\\java\\com\\zhwl\\live\\service\\"+ engName +"Service.java");
//        File service =new File(projectPath+"/src/main/java/com/l/dao/"+ engName +"Service.java");
        File serviceStub =new File("D:\\BaiduNetdiskDownload\\xm\\zhwl-live-parent\\zhwl-live-service\\zhwl-live-service-main\\src\\main\\java\\com\\zhwl\\live\\service\\stub\\"+ engName +"ServiceStub.java");
//        File serviceStub =new File(projectPath+"/src/main/java/com/l/dao/"+ engName +"ServiceStub.java");
        File serviceImpl =new File("D:\\BaiduNetdiskDownload\\xm\\zhwl-live-parent\\zhwl-live-service-impl\\zhwl-live-service-impl-main\\src\\main\\java\\com\\zhwl\\live\\service\\impl\\"+ engName +"ServiceImpl.java");
//        File serviceImpl =new File(projectPath+"/src/main/java/com/l/dao/"+ engName +"ServiceImpl.java");
        String inVoFolderStr = "D:\\BaiduNetdiskDownload\\xm\\zhwl-live-parent\\zhwl-live-portal\\zhwl-live-portal-admin\\src\\main\\java\\com\\zhwl\\live\\entity\\vo\\input\\"+lowerEngName+"\\";
        File inVoFolder = new File(inVoFolderStr);
        inVoFolder.mkdirs();
        File inVo =new File(inVoFolderStr + engName +"InVo.java");
        String inDtoFolderStr = "D:\\BaiduNetdiskDownload\\xm\\zhwl-live-parent\\zhwl-live-entity\\zhwl-live-entity-main\\src\\main\\java\\com\\zhwl\\live\\dto\\input\\"+lowerEngName+"\\";
        File inDtoFolder = new File(inDtoFolderStr);
        inDtoFolder.mkdirs();
        File inDto =new File(inDtoFolderStr + engName +"InDto.java");
        File outVo =new File(projectPath+"/src/main/java/com/l/domain/"+ engName +"outVo.java");
        String outDtoFolderStr = "D:\\BaiduNetdiskDownload\\xm\\zhwl-live-parent\\zhwl-live-entity\\zhwl-live-entity-main\\src\\main\\java\\com\\zhwl\\live\\dto\\output\\"+lowerEngName+"\\";
        File outDtoFolder = new File(outDtoFolderStr);
        outDtoFolder.mkdirs();
        File outDto =new File(outDtoFolderStr + engName +"OutDto.java");
        FileWriter writer;
        try {
            writer(serviceCode, serviceStubCode, serviceImplCode, service, serviceStub, serviceImpl);

            writer(inVoCode, inDtoCode, outVoCode, inVo, inDto, outVo);
            writer = new FileWriter(outDto);
            writer.write(outDtoCode);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static void writer(String inVoCode, String inDtoCode, String outVoCode, File inVo, File inDto, File outVo) throws IOException {
        FileWriter writer;
        writer = new FileWriter(inVo);
        writer.write(inVoCode);
        writer.flush();
        writer = new FileWriter(inDto);
        writer.write(inDtoCode);
        writer.flush();
        writer = new FileWriter(outVo);
        writer.write(outVoCode);
        writer.flush();
    }

}
